package com.cyanite.playlv2api.parsers.json;

import com.cyanite.playlv2api.types.Secret;

import org.json.JSONException;
import org.json.JSONObject;

public class SecretParser extends AbstractParser<Secret> {

    @SuppressWarnings("unchecked")
    @Override
    public Secret parse(JSONObject json) throws JSONException {
        Secret obj = new Secret();
        if (json.has("gid")) {
            obj.setId(String.valueOf(json.getInt("gid")));
        }
        if (json.has("name")) {
            obj.setTitle(json.getString("name"));
        }
        if (json.has("uid")) {
            obj.setUserId(String.valueOf(json.getInt("uid")));
        }
        if (json.has("nick")) {
            obj.setUserName(json.getString("nick"));
        }
        if (json.has("shout")) {
            obj.setShout(json.getString("shout"));
        }
        if (json.has("photo")) {
            obj.setPhoto(json.getString("photo"));
        }
        if (json.has("date")) {
            obj.setPostDate(json.getString("date"));
        }
        if (json.has("lat")) {
            obj.setLatitude(json.getString("lat"));
        }
        if (json.has("lng")) {
            obj.setLongitude(json.getString("lng"));
        }
        if (json.has("views")) {
            obj.setReviews(json.getInt("views"));
        }
        if (json.has("address")) {
            obj.setAddress(json.getString("address"));
        }
        if (json.has("list")) {
            obj.setWatchers(
                new GroupParser(
                    new UserParser()).parse(json.getJSONArray("list")));
        }
        return obj;
    }
}